var MyTable={
    searchForm:"searchForm",
    searchUrl:"/wxuser/list",
	tableId:"lgTable",
	table:null,
	prefix:"/wxuser/"
};

$(function() {
    var defaultColunms = MyTable.initColumn();
    var table = new BSTable(MyTable.tableId, MyTable.searchUrl,defaultColunms);
	table.setQueryParams(getFormJson(MyTable.searchForm));
	table.setSortName("asc");
	table.setSortOrder("gmt_create");
	MyTable.table = table.init(0);
	//loadTreeData();
});
function reLoad() {
	MyTable.table.refresh(getFormJson(MyTable.searchForm));
}
function resetSearch(){
	cleanFormVal(MyTable.searchForm);
	MyTable.table.refresh(null);
}

MyTable.initColumn = function () {
    var columns =  [
		{checkbox : true},
		{field : 'nickname',title : '昵称'},
		{field : 'headImgUrl',title : '头像',align : 'center',
			formatter : function(value, row, index) {
				if (value) {
					return '<img src="'+value+'" style="width:30px;height:30px"></img>';
				} else {
					return '';
				}
			}
		},
		{field : 'city',title : '城市'},
		{field : 'tel', title : '电话'},
		{field : 'email', title : '邮箱'},
		{field : 'userName', title : '真实姓名'},
		{field : 'sex',title : '性别',align : 'center',
			formatter : function(value, row, index) {
				if (value == '1') {
					return '<span class="label label-danger">男</span>';
				} else if (value == '2') {
					return '<span class="label label-primary">女</span>';
				}
			}
		},
		{field : 'subscribe',title : '关注状态',align : 'center',
			formatter : function(value, row, index) {
				if (value == '1') {
					return '<span class="label label-danger">未关注</span>';
				} else if (value == '0') {
					return '<span class="label label-primary">已关注</span>';
				}
			}
		},
		{field : 'isApproval',title : '审核状态',align : 'center',
			formatter : function(value, row, index) {
				if (value == '0') {
					return '<span class="label label-danger">未审核</span>';
				} else if (value == '1') {
					return '<span class="label label-primary">已审核</span>';
				}
			}
		},
		{field : 'subscribeTime', title : '关注时间'},
		{
			title : '操作',
			field : 'id',
			align : 'center',
			formatter : function(value, row, index) {
				var e = '<a  class="btn btn-primary btn-sm ' + editBtn + '" href="#" mce_href="#" title="审核" onclick="edit(\''
				+ row.id
				+ '\',1)"><i class="fa fa-check "></i></a> ';
			var d = '<a class="btn btn-warning btn-sm ' + editBtn + '" href="#" title="驳回审核"  mce_href="#" onclick="edit(\''
				+ row.id
				+ '\',0)"><i class="fa fa-remove"></i></a> ';
			return e + d;
			}
		} ];
    return columns;
};


function edit(wxuid,f){
	var mess=f==0?"确定要驳回审核？":"确定要审核通过吗？";
    var config={
			url : MyTable.prefix+"/update",
			data:{"id":wxuid,"isApproval":f},
			sureDo:true,
			msg:mess
	}
	EasyAjax.post_json(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}

function delRows(userId){
	var rows=checkSelect();
	if(!rows)
	return;
    var config={
			url : MyTable.prefix+"/deleteRows",
			data: {"ids" : rows},
			sureDo:true,
			msg:"确定删除记录？"
	}
	EasyAjax.post(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}

function move(){
	var rows=checkSelect();
	if(!rows)
	return;
	layer.open({
		type : 2,
		title : '给用户打标签',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '520px' ],
		content : MyTable.prefix+'/move?ids='+rows
	});
}




function checkSelect(){
	var rows = $('#'+MyTable.tableId).bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
	if (rows.length == 0) {
		layer.msg("请选择要操作的用户");
		return null;
	}else{
		var ids = new Array();
		$.each(rows, function(i, row) {
			ids[i] = row.id;
		});
		return ids;
	}
}
